package wetalk.software.bupt.com.wetalk.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.List;

import wetalk.software.bupt.com.wetalk.R;
import wetalk.software.bupt.com.wetalk.model.po.SearchMessageRecord;

/**
 * Created by Administrator on 2018/1/11 0011.
 */

public class SearchListAdapter extends ArrayAdapter<SearchMessageRecord> implements Filterable {
    private LayoutInflater inflater;
    private List<SearchMessageRecord> mData;
    private Context mContext;
    private int resourceId;

    public SearchListAdapter( Context context,int textViewResourceId,List<SearchMessageRecord> objects) {
        super(context,textViewResourceId,objects);
        resourceId = textViewResourceId;
        inflater = LayoutInflater.from(context);
        this.mContext = context;
        mData = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final SearchMessageRecord item = mData.get(position);
        View view;
        SearchListAdapter.ViewHolder viewHolder;

        if (convertView == null) {
            view = inflater.inflate(resourceId, parent, false);
        }else{
            view = convertView;
        }
        viewHolder = new SearchListAdapter.ViewHolder();
        viewHolder.iv_recent_avatar = (ImageView) view.findViewById(R.id.iv_recent_avatar);
        viewHolder.tv_recent_name = (TextView) view.findViewById(R.id.tv_recent_name);
        viewHolder.tv_recent_msg = (TextView) view.findViewById(R.id.tv_recent_msg);
        viewHolder.tv_recent_time = (TextView) view.findViewById(R.id.tv_recent_time);
        viewHolder.tv_recent_unread = (TextView) view.findViewById(R.id.tv_recent_unread);
        viewHolder.tv_recent_unread.setVisibility(View.GONE);

//填充数据
        viewHolder.iv_recent_avatar.setImageResource(R.mipmap.a1);
        viewHolder.tv_recent_name.setText(item.getUserName());
        viewHolder.tv_recent_msg.setText("查询到"+item.getCount()+"条相关数据...");
        viewHolder.tv_recent_time.setText(new SimpleDateFormat("HH:mm").format(item.getTime()));
        return view;
    }
    class ViewHolder{
        ImageView iv_recent_avatar;
        TextView tv_recent_name,tv_recent_msg,tv_recent_time,tv_recent_unread;
    }
}
